//
//  CXHAdImpressionTimer.h
//  Test
//
//  Created by Cdionysus on 2019/1/29.
//  Copyright © 2019 Cdionysus. All rights reserved.
//

#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>

@protocol CXHAdImpressionTimerDelegate <NSObject>

- (void)adViewWillLogImrepssion:(UIView *)adView;

@end

@interface CXHAdImpressionTimer : NSObject

@property (nonatomic, weak) id<CXHAdImpressionTimerDelegate> delegate;

+ (BOOL)visibilityView:(UIView *)view percent:(CGFloat)percent;

- (instancetype)init NS_UNAVAILABLE;
+ (instancetype)new NS_UNAVAILABLE;

/**
 初始化一个视图的监听对象, 然后回调给外部该视图是否达到展示要求

 @param requiredSecondsForImpression 展示时间 [0, infinite]
 @param requiredViewVisibilityPixels 展示像素 [0, infinite]
 */
- (instancetype)initWithRequiredSecondsForImpression:(NSTimeInterval)requiredSecondsForImpression requiredViewVisibilityPixels:(CGFloat)requiredViewVisibilityPixels NS_DESIGNATED_INITIALIZER;

/**
 初始化一个视图的监听对象, 然后回调给外部该视图是否达到展示要求

 @param requiredSecondsForImpression 展示时间 [0, infinite]
 @param visibilityPercentage 视图展示比例 [0, 1], 1代表100%
 */
- (instancetype)initWithRequiredSecondsForImpression:(NSTimeInterval)requiredSecondsForImpression requiredViewVisibilityPercentage:(CGFloat)visibilityPercentage NS_DESIGNATED_INITIALIZER;

- (void)startTrackingView:(UIView *)adView;

@end

static inline BOOL CXHViewIsVisible(UIView *view);
static inline BOOL CXHViewHasHiddenAncestor(UIView *view);
static inline BOOL CXHViewIntersectsParentWindow(UIView *view);
static inline BOOL CXHViewIntersectsParentWindowWithPercent(UIView *view, CGFloat percentVisible);
static inline UIWindow * CXHViewGetParentWindow(UIView *view);

